import resources.RegistNetPropertyBundle;
import registnet.dao.CoursePeer;
import registnet.dao.CourseOfferingPeer;
import java.io.PrintStream;
import java.io.File;


registnet.dao.SectionConfigurationPeer sectionConfigurationPeer = new registnet.dao.SectionConfigurationPeer();
registnet.dao.CoursePeer coursePeer = new registnet.dao.CoursePeer();
registnet.dao.SectionConfiguration sectionConfiguration;
registnet.dao.SystemPropertiesPeer spp = new registnet.dao.SystemPropertiesPeer();


List data = new Vector();
List resultSet = new Vector();

String _add = bundle.getProperty("registnet.module.data_management.actions.menu.add");
String _edit = bundle.getProperty("registnet.module.data_management.actions.menu.edit");
String _delete = bundle.getProperty("registnet.module.data_management.actions.menu.delete");
String _import = bundle.getProperty("registnet.module.data_management.actions.menu.import");
String _search = bundle.getProperty("registnet.module.data_management.actions.menu.search");
String _successful = bundle.getProperty("registnet.successful");


String _proceed = bundle.getProperty("registnet.messages.proceed");
String _check = bundle.getProperty("registnet.messages.check");
String _successful = bundle.getProperty("registnet.messages.successful");
String _failed = bundle.getProperty("registnet.messages.failed");
String _select_one = bundle.getProperty("registnet.messages.select_one");
String _selected = bundle.getProperty("registnet.messages.selected");

String _user_type = session.getAttribute("_user_type");
String _office = session.getAttribute("_office");


String _lec = "Lecture";
String _lab = "Laboratory";
final int LECTURE_COUNT = 0;
final int LAB_COUNT = 1;
final int STUDENT_COUNT = 2;

String _parentCourse;
String _instance = "Section Configuration";
String sectionType;

boolean isShowingInfo;
boolean isSearching;
boolean hasLab=false, hasRecit=false;
boolean isShowingInfo;
boolean isLaboratorySection;
boolean isSearching;

ArrayList alc = new ArrayList();
Map mu = new HashMap();

SimpleTreeNode root = new SimpleTreeNode("ROOT", alc);

public class MyTreeitemRenderer implements TreeitemRenderer {

	public void render(Treeitem item, Object data) throws Exception {
		
		String str = (String)data.getData();
	
		Treerow tr = null;
		
		Treecell tc = new Treecell(str);
		if(item.getTreerow()==null){
			tr = new Treerow();
			tr.setParent(item);
			try{
				item.setId(str + "_course");
			}catch(Exception e){}
		}else{
			tr = item.getTreerow(); 
			tr.getChildren().clear();
		}
		tc.setParent(tr);
	}
}

public class SectionTreeitemRenderer implements TreeitemRenderer {

	public void render(Treeitem item, Object data) throws Exception {
		
		String str = (String)data.getData();
	
		Treerow tr = null;
		
		Treecell tc = new Treecell(str);
		if(item.getTreerow()==null){
			tr = new Treerow();
			tr.setParent(item);
			try{
				item.setId(str + "_section");
				item.setOpen(true);
			}catch(Exception e){}
		}else{
			tr = item.getTreerow(); 
			tr.getChildren().clear();
		}
		tc.setParent(tr);
	}
}

void showAll(){
	//data = (new registnet.dao.CoursePeer()).getCourseByconfiguration(_office);
	//instance_list.setModel(new ListModelList(data));
	//instance_list.setItemRenderer(new MyItemRenderer());
}

private class SelectEventListener implements EventListener {
	
	public SelectEventListener (){
	}
			
	public void onEvent(Event event) throws UiException {
		showInfo();
	}
}	

private class CancelEventListener implements EventListener {
	public SubmitEventListener (){
	}
			
	public void onEvent(Event event) throws UiException {
		instance_tree.clearSelection();
		try{
			title.setValue("");
			contents.removeChild(contents.getFirstChild());
		} catch (Exception e) {}
	}
}

private class SearchEventListener implements EventListener {
	
	public SearchEventListener (){
	}
			
	public void onEvent(Event event) throws UiException {
		
		int isConfirmed = Messagebox.show("Do you want to use the Search Result Viewer?", "", Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
		if (isConfirmed == Messagebox.YES){
			resultSet = sectionConfiguration.searchSection(section_code.value, section_name.value);
			showSearchResultViewer();
		}
		else
			returnSearchResults();
			
		try{
			title.setValue("");
			contents.removeChild(contents.getFirstChild());
		} catch (Exception e) {}
	}
}


public void retrieveObjects(){
	alc.clear();
	data.clear();
	int unitId = (new registnet.dao.UnitPeer()).getUnitId(_office);
	List courses = coursePeer.getCoursesByUnit(unitId);
	for(int i=0; i<courses.size(); i++){
		List sectionConfigurations = sectionConfigurationPeer.getAllSectionConfigurationsByCourse(courses.get(i).getCourseId());
		ArrayList alu = new ArrayList();
		if(sectionConfigurations != null)
			for(int j=0; j<sectionConfigurations.size(); j++){
				data.add(sectionConfigurations.get(j));
				SimpleTreeNode stnSection = new SimpleTreeNode(sectionConfigurations.get(j).getSectionConfigurationName(), new ArrayList());
				alu.add(stnSection);
			}
		mu.put(courses.get(i).getCourseCode(), alu);
		SimpleTreeNode stnCourse = new SimpleTreeNode(courses.get(i).getCourseCode(), alu);
		alc.add(stnCourse);
	}

	SimpleTreeNode root = new SimpleTreeNode("ROOT", alc);
	SimpleTreeModel stm = new SimpleTreeModel(root);
	instance_tree.setModel(stm);
	instance_tree.setTreeitemRenderer(new MyTreeitemRenderer());
}

void returnSearchResults(){

	data.clear();
	
	resultSet = sectionConfiguration.searchSection(course_code.value, section_name.value);
	
	ListIterator li = resultSet.listIterator();
	while(li.hasNext()){
		data.add(((registnet.dao.Section)li.next()).getCourseCode());
	}

	instance_list.setModel(new ListModelList(data));
	instance_list.setItemRenderer(new MyItemRenderer());
}

void showInfo(){
	isShowingInfo = true;
	isSearching = false;
	
	
	if (contents.getFirstChild() != null){
		contents.removeChild(contents.getFirstChild());
	}
	try{
		if (instance_tree.getSelectedCount() == 1){
			
			sectionConfiguration = sectionConfigurationPeer.getSectionConfiguration(coursePeer.getCourseId(instance_tree.getSelectedItem().getParent().getLinkedTreerow().getParent().getLabel()), instance_tree.getSelectedItem().getLabel());
			title.setValue(coursePeer.getCourse(sectionConfiguration.getCourseId()).getCourseCode());
			Component show_configuration_form = Executions.createComponents("/WEB-INF/macros/data_management/section_configuration_form.zul", contents, null);
			int[] stat = getStatistics(show_configuration_form.getFellow("rows"));
			show_configuration_form.getFellow("section_grid").setVisible(true);
			show_configuration_form.getFellow("statistics").setVisible(true);
			show_configuration_form.getFellow("course_code_l").setValue(coursePeer.getCourse(sectionConfiguration.getCourseId()).getCourseCode());
			show_configuration_form.getFellow("configuration_name_l").setValue(sectionConfiguration.getSectionConfigurationName());
			if(sectionConfiguration.getIsActivated()==1)
				show_configuration_form.getFellow("activated_l").setValue("Yes");
			else
				show_configuration_form.getFellow("activated_l").setValue("No");
			
			show_configuration_form.getFellow("lecture_count").setValue(stat[LECTURE_COUNT]+"");
			show_configuration_form.getFellow("lab_count").setValue(stat[LAB_COUNT]+"");
			show_configuration_form.getFellow("student_count").setValue(stat[STUDENT_COUNT]+"");
			
			if(stat[LECTURE_COUNT] == 0)
				show_configuration_form.getFellow("no_sections").setVisible(true);
			
			show_configuration_form.getFellow("save_btn").detach();
			show_configuration_form.getFellow("cancel_btn").detach();
		}
		else if (instance_tree.getSelectedCount() > 1)
			title.setValue("" + instance_tree.getSelectedCount() + " " + _instance + " " + _selected);
		else
			title.setValue("");
	}catch (Exception e) { title.setValue(""); }
}


void showForm(String action){

	isShowingInfo = false;
	isSearching = false;

	try{
		contents.removeChild(contents.getFirstChild());
	} catch (Exception e) {}

	
	if (action.equals(_edit)){
		if(instance_tree.getSelectedCount() == 1){
			Component edit_configuration_form = Executions.createComponents("/WEB-INF/macros/data_management/section_configuration_form.zul", contents, null);
			sectionConfiguration = sectionConfigurationPeer.getSectionConfiguration(coursePeer.getCourseId(instance_tree.getSelectedItem().getParent().getLinkedTreerow().getParent().getLabel()),instance_tree.getSelectedItem().getLabel());
			title.setValue(coursePeer.getCourse(sectionConfiguration.getCourseId()).getCourseCode());
			edit_configuration_form.setParent(contents);
			show_configuration_form.getFellow("section_grid").setVisible(false);
			edit_configuration_form.getFellow("course_code_l").setValue(coursePeer.getCourse(sectionConfiguration.getCourseId()).getCourseCode());
			edit_configuration_form.getFellow("configuration_name").setValue(sectionConfiguration.getSectionConfigurationName());
			
			if(sectionConfiguration.getIsActivated()==1)
				edit_configuration_form.getFellow("activated").setValue("Yes");
			else
				edit_configuration_form.getFellow("activated").setValue("No");
			
			
			edit_configuration_form.getFellow("save_btn").addEventListener("onClick", new SubmitEventListener(action));
			edit_configuration_form.getFellow("cancel_btn").addEventListener("onClick", new CancelEventListener());
		}
		else{
			alert(_select_one + " " + _instance);
		}
	}
	
	else if (action.equals(_add)){
		if(instance_tree.getSelectedItem() != null){
			
			String courseCode = instance_tree.getSelectedItem().getLabel();
			if(checkCourse(courseCode)){
			Component add_configuration_form = Executions.createComponents("/WEB-INF/macros/data_management/section_configuration_form.zul", contents, null);
			title.setValue(_add + " " + _instance);
			add_configuration_form.setParent(contents);
			add_configuration_form.getFellow("section_grid").setVisible(false);
			add_configuration_form.getFellow("course_code_l").setValue(courseCode);
			add_configuration_form.getFellow("activated").setSelectedIndex(1);
			add_configuration_form.getFellow("save_btn").addEventListener("onClick", new SubmitEventListener(action));
			add_configuration_form.getFellow("cancel_btn").addEventListener("onClick", new CancelEventListener());
			
			}
			else
				alert("Select a course first.");
		}
		else
			alert("Select a course first.");
	}
	
	
}

setSectionType(String type){
	sectionType=type;
	modal_win.detach();
}


boolean checkCourse(String courseCode){
	registnet.dao.Course course = (new registnet.dao.CoursePeer()).getCourse(courseCode);
	if(course==null){
		return false;
	}
	else{
		return true;
	}
}

/*
void delete(){
	if(instance_list.getSelectedCount() != 0){
		int isConfirmed = Messagebox.show(_proceed, _delete + " " + _instance, Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
		if (isConfirmed == Messagebox.YES){
			boolean isError = false;
			int errorCount = 0;
			Iterator i = instance_list.getSelectedItems().iterator();
			instance_list.renderAll();
			alert(i.next());
			while(i.hasNext()){
				String string = i.next().string;
				int temp = sectionConfiguration = sectionConfigurationPeer.getSectionConfiguration(coursePeer.getCourseId(instance_tree.getSelectedItem().getParent().getLinkedTreerow().getParent().getLabel()), string);
				if (sectionConfiguration.deleteSection(temp))
					data.remove(string);
				else{
					isError = true;
					errorCount++;
				}
			}
			instance_list.setModel(new ListModelList(data));
			if (isError){ 
				alert(_delete + " " + _failed + ": " + errorCount + " " + _instance);
				title.setValue(_delete + " " + _instance + " " + _failed);
			}
			
			else{
				title.setValue(_delete + " " + _instance + " " + _successful);
				if (contents.getFirstChild() != null){
					contents.removeChild(contents.getFirstChild());
				}
			}
		}			
	}
}

*/
void createNewSection(){
		
		
		if (isValid()){
			title.setValue(_add + " " + _instance + " " + _successful);
			int courseId = coursePeer.getCourseId(course_code_l.value);
			if(sectionConfigurationPeer.createNewSectionConfiguration(courseId, configuration_name.value, Integer.parseInt(activated.getSelectedItem().getValue())) != null){
				retrieveObjects();
				macro_win.getFellow(course_code_l.value + "_course").setOpen(true);
				try{
					contents.removeChild(contents.getFirstChild());
				} catch (Exception e) { }
			}
			else
				alert("Please check info supplied");
		}
		else
			alert("Please check info supplied");
}

void editSection(){
		
	if (isValid()){
			title.setValue(_add + " " + _instance + " " + _successful);
			int courseId = coursePeer.getCourseId(course_code_l.value);
			
		if(sectionConfigurationPeer.updateSectionConfiguration(sectionConfigurationPeer.getSectionConfigurationId(courseId,instance_tree.getSelectedItem().getLabel() ), courseId, configuration_name.value, Integer.parseInt(activated.getSelectedItem().getValue()))){
			retrieveObjects();
			macro_win.getFellow(course_code_l.value + "_course").setOpen(true);
			title.setValue(_edit + " " + _instance + " " + _successful);
			try{
				contents.removeChild(contents.getFirstChild());
			} catch (Exception e) { }
		}
		else
			alert(_check);
	}
	else
		alert(_check);
}

boolean isValid(){
	if (configuration_name.value != null && configuration_name.value.trim().length() == 0)
		return false;
	return true;
}

private class SubmitEventListener implements EventListener {
	String submitType;
	public SubmitEventListener (String submitType){
		this.submitType = submitType; 
	}
			
	public void onEvent(Event event) throws UiException {
		if(this.submitType.equals(_add))
			createNewSection();
		else if (this.submitType.equals(_edit))
			editSection();
	}
}

void filter(String string){

	ListIterator i = data.listIterator();
	List list = new java.util.Vector();
	while(i.hasNext()){
		String temp = i.next(); 
		if(temp.toUpperCase().startsWith(string.toUpperCase())){
			list.add(temp);
		}
	}
	instance_list.getModel().clear();
	instance_list.getModel().addAll(list);
}

void showSearchForm(){
	isSearching = true;
	isShowingInfo = false;

	try{
		contents.removeChild(contents.getFirstChild());
	} catch (Exception e) {}

	Component search_section_form = Executions.createComponents("/WEB-INF/macros/data_management/section_configuration_form.zul", contents, null);
	title.setValue("Search for " + _instance);
	search_section_form.setParent(contents);
	search_section_form.getFellow("search_btn").addEventListener("onClick", new SearchEventListener());
	search_section_form.getFellow("cancel_btn").addEventListener("onClick", new CancelEventListener());
}

void showSearchResultViewer(){
	Tabbox stage = macro_win.getParent().getParent().getTabbox();
	Tab tab = new Tab("Search Result");
	Tabs tabs = stage.getTabs();
	tab.setClosable(true);
	tab.setParent(tabs);
	stage.setSelectedTab(tab);
		
	Tabpanel tabpanel = new Tabpanel();
	tabpanel.setSclass("background_light_blue");
	
	
	Component search_result_viewer = Executions.createComponents("/WEB-INF/macros/search_result_viewer.zul", tabpanel, null);
		
	Tabpanels tabpanels = stage.getTabpanels();
	tabpanel.setParent(tabpanels);
	stage.setSelectedPanel(tabpanel);
}

private class FieldItemRenderer implements ListitemRenderer {
	public void render(Listitem item, java.lang.Object data) {
		new Listcell(data).setParent(item);
	}
}
			
private class DataItemRenderer implements ListitemRenderer {
	public void render(Listitem item, java.lang.Object data) {
		for(int i=0; i<data.length; i++)
			new Listcell(data[i]).setParent(item);
	}
}
	
void retrieveFieldNames(){
	List data = new registnet.dao.Section().getFields();		  
	String[] listModel = new String[data.size()];
	for (int i=0; i<data.size(); i++)
		listModel[i] = data.get(i);
	ListModel strset = new ListModelList(listModel);
	field_list.setModel(strset);
	field_list.setItemRenderer(new FieldItemRenderer());
}


private class FieldEventListener implements EventListener {
	
	public FieldEventListener (){
	}

	public void onEvent(Event event) throws UiException {
		result_list.removeChild(result_list.getListhead());
		Listhead listhead = new Listhead();
		listhead.setParent(result_list);
		Object[] selected = field_list.getSelectedItems().toArray();
		for (int i=0; i<selected.length; i++){
			Listheader lh = new Listheader(field_list.getModel().get(selected[i].getIndex()));
			lh.setParent(listhead);
		}
		
		
		String[] temp = new String[resultSet.size()];
		int numRows = temp.length;
		String[][] listModel = new String[numRows][selected.length];
		for (int i=0; i<temp.length; i++){
			for (int j=0; j<selected.length; j++){
				if (field_list.getModel().get(selected[j].getIndex()).equals("Section Code"))
					listModel[i][j] = resultSet.get(i).getSectionCode();
				else if (field_list.getModel().get(selected[j].getIndex()).equals("Section Name"))
					listModel[i][j] = resultSet.get(i).getSectionName();
			}
		}
		ListModel strset = new ListModelList(listModel);
		result_list.setModel(strset);
		result_list.setItemRenderer(new DataItemRenderer());
		
	}
}

showSections(){
	Tabbox stage = macro_win.getParent().getParent().getTabbox();
	Tab tab = new Tab(coursePeer.getCourse(sectionConfiguration.getCourseId()).getCourseCode() +"_" + instance_tree.getSelectedItem().getLabel());
	Tabs tabs = stage.getTabs();
	tab.setClosable(true);
	tab.setParent(tabs);
	stage.setSelectedTab(tab);
		
	Tabpanel tabpanel = new Tabpanel();
	tabpanel.setSclass("background_light_blue");
	
	Tabpanels tabpanels = stage.getTabpanels();
	tabpanel.setParent(tabpanels);
	
	Component sections_viewer = Executions.createComponents("/WEB-INF/macros/data_management/section.zul", tabpanel, null);
	sections_viewer.getFellow("config_id").setValue(""+sectionConfiguration.getSectionConfigurationId());	
	
	int hasLab = (new registnet.dao.CoursePeer()).getCourse(sectionConfiguration.getCourseId()).getHasLaboratory();
	if(hasLab==1)
		sections_viewer.getFellow("lab_menu").setVisible(true);
	sections_viewer.setParent(tabpanel);
	stage.setSelectedPanel(tabpanel);
	
}

int[] getStatistics(Rows rows){
	int[] stat = new int[3];
	stat[0]=0;
	stat[1]=0;
	stat[2]=0;
	List lectures = (new registnet.dao.SectionPeer()).getLectureSections(sectionConfiguration.getSectionConfigurationId());
	for(int i=0; i<lectures.size(); i++){
		int lecStudentCount = 0;
		lecStudentCount = lectures.get(i).getStudentCount();
		
		Group lec = new Group();
		lec.setLabel(lectures.get(i).getSectionName()+"   [" + lecStudentCount + "]");
		lec.setParent(rows);
		
		List labs = (new registnet.dao.SectionPeer()).getLaboratory(sectionConfiguration.getSectionConfigurationId(), lectures.get(i).getSectionName());
		int labSize = labs.size();
		if(labSize == 0)
			lec.setHeight("2px");
		for(int j=0; j<labSize; j++){
			Row row = new Row();
			Label lab = new Label();
			int labStudentCount = 0;
			labStudentCount = labs.get(j).getStudentCount();
			lab.setValue(labs.get(j).getSectionName()+"   [" + labStudentCount + "]");
			lab.setParent(row);
			row.setParent(rows);
		}
		
		
		try{	
			stat[LAB_COUNT] += labSize;
			stat[STUDENT_COUNT] += lecStudentCount;
		}
		catch(Exception e){}	
	}
	
	stat[LECTURE_COUNT] = lectures.size();
	return stat;
}

activate(){
	int sectionConfigurationId = sectionConfiguration.getSectionConfigurationId();
	sectionConfigurationPeer.updateSectionConfiguration(sectionConfigurationId, 1);
	List configs = sectionConfigurationPeer.getAllSectionConfigurationsByCourse(sectionConfiguration.getCourseId());
	for(int i=0; i<configs.size(); i++){
		if(configs.get(i).getSectionConfigurationId()!= sectionConfigurationId && configs.get(i).getIsActivated() == 1)
			sectionConfigurationPeer.updateSectionConfiguration(configs.get(i).getSectionConfigurationId(), 0);
	}
	showInfo();
}

finalize(){
	String courseCode = instance_tree.getSelectedItem().getLabel();
	CourseOfferingPeer courseOfferingPeer = new CourseOfferingPeer();
	if(checkCourse(courseCode)){
		int courseId = coursePeer.getCourseId(courseCode);
		int isConfirmed = Messagebox.show(_proceed,"Finalize " + _instance, Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (isConfirmed == Messagebox.YES){
				int sectionCofigurationId = sectionConfigurationPeer.getActiveSectionConfigurationId(courseId);
				if(sectionConfigurationId != null){
					List sections = (new registnet.dao.SectionPeer()).getSectionsBySectionConfiguration(sectionCofigurationId);
					registnet.dao.CourseOfferingPeer courseOfferingPeer = new registnet.dao.CourseOfferingPeer();
					if(sections.size!=0){
						for(int i=0; i<sections.size(); i++){
							
							if(courseOfferingPeer.createNewCourseOffering(courseId, sections.get(i).getSectionName(), spp.getSystemProperties().getSemester(), spp.getSystemProperties().getAcademicYear().toString(), sections.get(i).getLaboratoryDay(), sections.get(i).getLectureDay(),sections.get(i).getRecitationDay(), sections.get(i).getLaboratoryRoom(), sections.get(i).getLectureRoom(), sections.get(i).getRecitationRoom(), sections.get(i).getLaboratoryTime(), sections.get(i).getLectureTime(), sections.get(i).getRecitationTime(), sections.get(i).getLaboratoryInstructor(), sections.get(i).getLectureInstructor(), sections.get(i).getRecitationInstructor(), sections.get(i).getIsTeamTeach(), sections.get(i).getStudentCount()) == null){
								alert("Unable to finalize "+sections.get(i).getSectionName());
							}
						}
						title.setValue(courseCode +" sections successfully finalized using "+ sectionConfigurationPeer.getSectionConfiguration(sectionCofigurationId).getSectionConfigurationName()+ " configuration.");
					}
					else
						alert("No sections yet in " + sectionConfigurationPeer.getSectionConfiguration(sectionCofigurationId).getSectionConfigurationName()+ " configuration.");
				}
				else
					alert("No active section configuration yet.");
			}
			
		/*
		if(courseOfferingPeer.getCourseOfferings(courseId, 1, "2008-2009").size() == 0){
			int isConfirmed = Messagebox.show(_proceed,"Finalize " + _instance, Messagebox.YES | Messagebox.NO, Messagebox.QUESTION);
			if (isConfirmed == Messagebox.YES){
				int sectionCofigurationId = sectionConfigurationPeer.getActiveSectionConfigurationId(courseId);
				if(sectionConfigurationId != null){
					List sections = (new registnet.dao.SectionPeer()).getSectionsBySectionConfiguration(sectionCofigurationId);
					registnet.dao.CourseOfferingPeer courseOfferingPeer = new registnet.dao.CourseOfferingPeer();
					if(sections.size!=0){
						for(int i=0; i<sections.size(); i++){
							if(courseOfferingPeer.createNewCourseOffering(courseId, sections.get(i).getSectionName(), 1, "2008-2009", sections.get(i).getLaboratoryDay(), sections.get(i).getLectureDay(),sections.get(i).getRecitationDay(), sections.get(i).getLaboratoryRoom(), sections.get(i).getLectureRoom(), sections.get(i).getRecitationRoom(), sections.get(i).getLaboratoryTime(), sections.get(i).getLectureTime(), sections.get(i).getRecitationTime(), sections.get(i).getLaboratoryInstructor(), sections.get(i).getLectureInstructor(), sections.get(i).getRecitationInstructor(), sections.get(i).getIsTeamTeach(), sections.get(i).getStudentCount()) == null){
								alert("Unable to finalize "+sections.get(i).getSectionName());
							}
						}
						title.setValue(courseCode +" sections successfully finalized using "+ sectionConfigurationPeer.getSectionConfiguration(sectionCofigurationId).getSectionConfigurationName()+ " configuration.");
					}
					else
						alert("No sections yet in " + sectionConfigurationPeer.getSectionConfiguration(sectionCofigurationId).getSectionConfigurationName()+ " configuration.");
				}
				else
					alert("No active section configuration yet.");
			}
		}
		else
			alert("Finalized already.");
		*/
	}
	else 
		alert("Select a course first.");
}